package org.malred.hotelsystem.activities.user;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

import org.malred.hotelsystem.R;
import org.malred.hotelsystem.activities.BaseActivity;
import org.malred.hotelsystem.fragment.admin.ManageAddFragment;
import org.malred.hotelsystem.fragment.admin.ManageHomeFragment;
import org.malred.hotelsystem.fragment.admin.ManageOrderFragment;
import org.malred.hotelsystem.fragment.user.UserHomeFragment;
import org.malred.hotelsystem.fragment.user.UserOrderFragment;

public class UserHomeActivity extends BaseActivity {
    private static final String TAG = "UserHomeActivity";
    Toolbar toolbar;
    BottomNavigationView bottomNavigationView;

    @Override
    protected int initLayout() {
        return R.layout.activity_user_home;
    }

    @Override
    protected void initView() {
        toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        bottomNavigationView = findViewById(R.id.user_bottom_nav);
    }

    @Override
    protected void initData() {
        // 默认首页选中
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.user_content, new UserHomeFragment()).commit();
        // 切换底部导航事件
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                if (item.getItemId() == R.id.home) {
                    getSupportFragmentManager().beginTransaction()
                            .replace(R.id.user_content, new UserHomeFragment()).commit();
                    return true;
                } else if (item.getItemId() == R.id.order) {
                    getSupportFragmentManager().beginTransaction()
                            .replace(R.id.user_content, new UserOrderFragment()).commit();
                    return true;
                }
                // return true 底部图标才会变
                return false;
            }
        });
    }
}